import { Node, mergeAttributes } from "@tiptap/core";
import { ReactNodeViewRenderer } from "@tiptap/react";
import { TagComponent } from "./TagComponent";

export default Node.create({
  name: "reactComponent",
  group: "block",
  atom: true,

  addAttributes() { 
    return {
      count: {
        default: 0
      }
    }
  },

  parseHTML() { 
    return [
      {
        tag: "react-component",
      }
    ]
  },

  renderHTML({ HTMLAttributes }) { 
    return ["react-component", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]
  },

  addNodeView() { 
    return ReactNodeViewRenderer(TagComponent);
  }
})